package combat;

import graphinterface.MouseDetector;

import java.util.ArrayList;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;

public class FenetreSecond {
	
	public int widthF, heightF;
	public int posX, posY;
	public Rectangle rectangleF;
	public String titleF;
	public Color colorTitre, colorFenetre;
	public boolean affiche;
	public ArrayList <MouseDetector> contenuF;
	public String pushed;
	
	
	
	public FenetreSecond(String titre,int x, int y, int width, int height, Color couleurTitre, Color couleurFenetre) throws SlickException{
		posX = x;
		posY = y;
		widthF = width;
		heightF = height;
		colorTitre = couleurTitre;
		colorFenetre = couleurFenetre;
		contenuF = null;
		pushed = null;
		
		rectangleF = new Rectangle(posX, posY, widthF, heightF);
		titleF = titre;
		affiche = false;
		
		
		
		
	}
	
	public void draw(GameContainer gc, Graphics g, boolean center){
		// marche que pour MouseDetector
		if (affiche){
			g.setColor(colorFenetre);
			g.draw(rectangleF);
			g.setColor(colorTitre);
			if (!center){
				g.drawString(titleF,posX + 2, posY + 2);
			}
			else{
				int taille = titleF.length() * 10;
				int ecart = (widthF - taille)/2;
				g.drawString(titleF,posX + ecart, posY + 2);
			}
			for (MouseDetector boutton : contenuF ){
				boutton.draw(g);
			}
				
				
		}
		
	}
	
	public void update(GameContainer gc){
		for (Object boutton : contenuF ){
			((MouseDetector) boutton).update(gc, 0);
			if ((boolean) ((MouseDetector) boutton).isPushed()){ //dat line!
				pushed = ((MouseDetector) boutton).getName();
				((MouseDetector) boutton).resetPushed();
			}
		}
	}
	
	public void updateWHide(GameContainer gc){
		for (Object boutton : contenuF ){
			((MouseDetector) boutton).update(gc, 0);
			if ((boolean) ((MouseDetector) boutton).isPushed()){ //dat line!
				pushed = ((MouseDetector) boutton).getName();
				((MouseDetector) boutton).resetPushed();
			}
		}
		if (pushed != null){
			this.cacher();
		}
	}
	
	/*public void add(MouseDetector boutton, int x, int y){
		
		
	}*/
	public int getPosX(){
		return this.posX;
	}
	
	public int getPosY(){
		return this.posY;
	}
	
	public String getPushed(){
		return this.pushed;
	}
	
	public void afficher(){
		this.affiche = true;
	}
	public void cacher(){
		this.affiche = false;
	}
	public void setContenu(ArrayList<MouseDetector> contenu){
		this.contenuF = contenu;
	}
	
	public boolean isShow(){
		return this.affiche;
	}
	
	public void initPushed(){
		this.pushed = null;
	}
}
